<?php 

/**
 * 返回json格式的数据
 * @范昭瑰
 * @DateTime  2017-07-06T17:29:19+0800
 * @param     [int]                   $status  [description]
 * @param     [string]                   $message [description]
 * @param     [array]                   $data    [description]
 * @return    [string]                            [description]
 */
function show($status, $message, $data=[])
{
	$data = [
		"status"	=> $status,
		"message"	=> $message,
		"data"		=> $data
	];

	return exit(json_encode($data));
}

/**
 * 获取登入用户的信息
 * @范昭瑰
 * @DateTime  2017-07-06T17:30:14+0800
 * @return    string      json字符串
 */
function getUserInfo()
{
	return session("userInfo");
}


function getUserName()
{
	return $_SESSION['userinfo']['username'];
	// return '老范';
}

/**
 * 检测是否登录
 * @return boolean 是否登录
 */
function check_login()
{
    if (!empty($_SESSION['userinfo']['id'])){
        return true;
    }else{
        return false;
    }
}

/**
 * hash密码
 */
function get_hash_password($password)
{
	return password_hash($password, PASSWORD_DEFAULT);
}
/**
 * hash验证
 */
function hash_verify($password, $hash)
{
	return password_verify($password , $hash);
}
/**
 * 是否有图标
 */
function hasIco($string)
{
	return empty($string) ? "<font color='red'>无图标</font>": $string ;
}

/**
 * 实例分页类
 */
function new_page($count, $limit=10)
{
	return new \Think\Page($count, $limit);
}

/**
 * 获取分页数据
 */
function getAskCateName($id)
{
	$m = M("ask_category");
	$cats = $m->select();
	foreach ($cats as $v) {
		if ($v["id"] == $id) {
			return $v["name"];
		}
	}
	return "<font color='red'>分类不存在</font>";
}

/**
 * Kindeditor 的图片上传
 * @AuthorHTL
 * @DateTime  2017-07-24T20:51:31+0800
 * @param     [type]                   $status [description]
 * @param     [type]                   $data   [description]
 * @return    [type]                           [description]
 */
function showKind($status, $data)
{
	if ($status == 0) {
		exit(json_encode([
			'error' => 0,
			'url' => $data
		]));
	}
	exit(json_encode([
			'error' => 1,
			'url' => "上传失败"
		]));
}